<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
Category[] catList;
Movie[] moviecatList;
catList=(Category[])session.getAttribute("catList");
moviecatList=(Movie[])session.getAttribute("moviecatList");
%>
<%@page import="com.beans.Category"%>
<%@page import="com.beans.Movie"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript">
function validateSelection(){
var flag = false;
var eleLength = document.addQueueForm.elements.length;
	for (i=0;i<eleLength;i++){
		 var type = addQueueForm.elements[i].type;
		if (type=="checkbox" && addQueueForm.elements[i].checked){
		flag = true;
		break;
		}
	}
	if(flag == false)
		{
		document.all("error").innerHTML  = "Please select atleast one Item to Add Queue";
		return false;
		}
	else{
		return true;
	}
}
</script>
</head>
<body>
<%@ include file="header.jsp" %>
<form id="searchMovieForm" name="searchMovieForm" method="POST" action="SearchMovieServlet">
<table>
		<tr>
		<td valign="top" align="left">
		<b>Category</b>
		</td>
		<td valign="top" align="left">
		<select name="category" size="1" >
			<%
			if(catList != null)
			{
				for(int i=0;i<catList.length;i++)
				{
			%>
				<option value='<%=catList[i].getCat_id() %>'><%=catList[i].getCat_name() %></option>
			<% 		
				}
			}
			%>
		</select>
		</td>
		<td>
		<input type="submit" value="Search">
		</td>
		</tr>
	</table><br>
	

</form>
<form id="addQueueForm" name="addQueueForm" method="POST" action="AddQueueServlet" onsubmit="return validateSelection();">
<div class ="inputColumn" id = "CartItems"  
				style="text-align: left; border: none; margin: auto;">	
				<div style="text-align:center;font-size:1em;font-family: sans serif;">
				<% String mname = (String)request.getAttribute("MovieName");
				
			if(mname != null){
			%>
			<label style="size: 25; color: green"><%=mname%></label>	<%} %>	
				<% String status = (String)request.getAttribute("status");
			if(status != null){
			%>
			<label style="size: 25; color: green"><%=status%></label>	<%} %>
			<label id ="error" style="size: 25; color: green"></label>	</div>
			<table align="center" border="1" style="border-style: dashed; background-color: rgb(254,252,180);">
			<%
			if(moviecatList != null)
			{
			%>
				<tr>
				<th align="center" style="color:red" bordercolor="red">No</th>
				<th align="center" style="color:red" bordercolor="red">Movie</th>
				<th align="center" style="color:red" bordercolor="red">Banner</th>
				<th align="center" style="color:red" bordercolor="red">ReleaseDate</th>
				<th align="center" style="color:red" bordercolor="red">Rent in $</th>
				<th align="center" style="color:red" bordercolor="red">Rating</th>
				<th align="center" style="color:red" bordercolor="red">Users Rated</th>
				</tr>
				<% 
				
				for(int i=0;i<moviecatList.length;i++)
				{
				%>
				<tr bordercolor="black" >
				 <td bordercolor="black">
					 	<input type="checkbox" value ='<%=moviecatList[i].getMovieId()%>' name="movieid"> 
					</td>
				  <td bordercolor="black">
					 	<label id ="MovieName" style="size: 25;"><%=moviecatList[i].getMovieName()%></label> 
					</td>
					<td bordercolor="black">
					 	<label id ="MovieBanner" style="size: 25;"><%=moviecatList[i].getMovieBanner()  %></label> 
					</td>
					<td bordercolor="black">
					 	<label id ="Release" style="size: 25;"><%=moviecatList[i].getReleaseDate()  %></label> 
					</td>
					<td bordercolor="black">
					 	<label id ="Rent" style="size: 25;"><%=moviecatList[i].getRent()  %></label> 
					</td>
					<td bordercolor="black">
					 	<label id ="Rating" style="size: 25;"><%=moviecatList[i].getRating()  %></label> 
					</td>
					<td bordercolor="black">
						<label id="NoRating" style="size: 35;"><%=moviecatList[i].getNo_of_ratings()   %></label>
					</td>
					
				</tr>
				<%
				}
				%>
				
			</table>
			<div style="text-align:center;color:red;font-size:2em;font-family: sans serif;">
			<input type="submit" value="Add to Queue" name="submit" align ="middle"/>
			</div>
				<%			
			}
			else
			{
			%>
			<font size="4"></font>
			<%
			}
			%>
	</div>
</form>

</body>
</html>